package course.ya.doc.from.code.model.lexer.project;

public class SyntaxTree {

    private NodeTree root;
    private NodeTree curentNode;
    private NodeTree dampNode;

    public SyntaxTree() {
        root = null;
        curentNode = root;
        dampNode = root;
    }

    public void insert(String data, boolean isNotParsed, boolean isGroup) {
        NodeTree newNode = new NodeTree();
        newNode.data = data;
        newNode.isNotParsing = isNotParsed;

        if (root == null) {
            root = newNode;
            curentNode = newNode;
            dampNode = newNode;
        } else {
            if (isGroup == false) {
                newNode.parent = curentNode;
                curentNode.references.add(newNode);
            } else {
                dampNode = curentNode;
                newNode.parent = curentNode;
                curentNode.references.add(newNode);
                curentNode = curentNode.references.get(curentNode.references.size() - 1);
            }
        }
    }

    public void jumpUp() {
        curentNode = curentNode.parent;
        dampNode = curentNode;
    }

    public void jumpUp(int count) {
        for (int i = 0; i < count; i++) {
            curentNode = curentNode.parent;
        }
        dampNode = curentNode;
    }

    public NodeTree getRoot() {
        return root;
    }

}
